function next(step){
    var frmdata=$("#joinapply_frm_main").serializeObject();

    if(step==1){
        if(server.isEmpty(frmdata.nickname)){
            pop_up('必须给大师取个名字');
            return;
        }
        if(server.isEmpty(frmdata.name)){
            pop_up('您的真实姓名');
            return;
        }
        if(server.isEmpty(frmdata.workYears)){
            pop_up('工作年限不能为空');
            return;
        }
        if(server.isEmpty(frmdata.agree)){
            pop_up("请同意《玄集平台易学老师入驻条款》");
            return;
        }
        $(".info1").hide();
        $(".info2").show();
        $("#flownode").val(2);
        $("#line1").attr('src','img/flow-line-done.png');
        $("#dot2").attr('src','img/flow-dot-done.png');


    }else if(step==2){
        if(server.isEmpty(frmdata.skills)){
            pop_up('最少选择一项技能');
            return;
        }
        $(".info1").hide();
        $(".info2").hide();
        $(".info3").show();
        $("#flownode").val(3);
        $("#line2").attr('src','img/flow-line-done.png');
        $("#dot3").attr('src','img/flow-dot-done.png');
    }else if(step==3){
        if(server.isEmpty(frmdata.idcard1)||server.isEmpty(frmdata.idcard2)){
            pop_up('上传身份证照片正反面');
            return;
        }
        if(server.isEmpty(frmdata.bgimage)){
            pop_up('上传背景图片');
            return;
        }
        $(".info1").hide();
        $(".info2").hide();
        $(".info3").hide();
        $(".info4").show();
        $("#flownode").val(4);
        $("#line3").attr('src','img/flow-line-done.png');
        $("#dot4").attr('src','img/flow-dot-done.png');

        var params = {};
        params.name = frmdata.name;
        params.nickname = frmdata.nickname;
        params.idcardPositive=frmdata.idcard1;
        params.idcardOtherside=frmdata.idcard2;
        params.skills = frmdata.skills;
        // params.specialty = frmdata.skills;
        params.workYears = frmdata.workYears;
        params.bgImage = frmdata.bgimage;

        params.sex=frmdata.sex;
        params.phone = frmdata.phone;
        params.country = frmdata.country;
        params.province = frmdata.province;
        params.city = frmdata.city;
        params.area=frmdata.area;
        params.birthday = new Date(frmdata.birthday);

        server.req('wechat/teacher/save',params,function (res) {
            // console.log(res);
            if(res.code==0){
                console.log("success");
            }
        },null,"POST")
    }else if(step==4){
        server.loadindex('page/home/home')
    }

};
function dealing() {
    $(".info1").hide();
    $(".info2").hide();
    $(".info3").hide();
    $(".info4").show();
    $("#line1").attr('src','img/flow-line-done.png');
    $("#dot2").attr('src','img/flow-dot-done.png');
    $("#line2").attr('src','img/flow-line-done.png');
    $("#dot3").attr('src','img/flow-dot-done.png');
    $("#line3").attr('src','img/flow-line-done.png');
    $("#dot4").attr('src','img/flow-dot-done.png');

}
var skills =new Array();
function selectSkill(id,title){

    var strClass = $("#skill"+id).attr('class');
    if(strClass=='skillA'){
        if(skills.length>=3){
            pop_up('最多可选三项');
            return;
        }
        $("#skill"+id).removeClass('skillA');
        $("#skill"+id).addClass('skillB');
        $("#skill"+id).css("color","white");
        addSkill(title);
        // console.log(skills);
    }else{
        $("#skill"+id).removeClass('skillB');
        $("#skill"+id).addClass('skillA');
        $("#skill"+id).css("color","#333333");
        removeSkill(title);
    }
    $("#skills").val(skills);
    // console.log(skills);
};
function addSkill(id){
    var isExist = 0;
    skills.forEach(function (value) {
        if(value==id)isExist = 1;
    })
    if(isExist==0){
        skills.push(id);
    }
};
function removeSkill(id){

    skills.forEach(function (value) {
        if(value==id){
            var index = skills.indexOf(id);
            skills.splice(index, 1);
        };
    })
};
//性别选择
function selectSex(sex) {
    if(sex==1){
        $("#nan").css("background-color","#dcdcdc");
        $("#nv").css("background-color","#ffffff");
        $("#sex").val(1);
    }else if(sex==0){
        $("#nan").css("background-color","#ffffff");
        $("#nv").css("background-color","#dcdcdc");
        $("#sex").val(0);
    }
};
//会员协议
function toagree(key) {
    server.loadindex('page/agree/agree','key='+key);
}
//点击上传文件

$(".uploadclass").change(function(e){
    $(this).upload({
        url:server.url+'/file/uploadFile',
        fileName:'file',

        onsuccess:function(r){
            $("#"+e.currentTarget.dataset.id).attr("src",r.data.url);
            $("#"+e.currentTarget.dataset.r).val(r.data.url);

        },

        onerror:function(e){
            console.log(e)
        },
        oncomplate:function(data){
            console.log(data);
        }
    });
});


//选择日期和时间
$("#time-format").datetimePicker({
    title: '选择出生日期',
    yearSplit: '年',
    monthSplit: '月',
    dateSplit: '日',
    times: function () {
        return [  // 自定义的时间
            {
                values: (function () {
                    var hours = [];
                    for (var i=0; i<24; i++) hours.push(i > 9 ? i : '0'+i);
                    return hours;
                })()
            },
            {
                divider: true,  // 这是一个分隔符
                content: '时'
            },
            {
                values: (function () {
                    var minutes = [];
                    for (var i=0; i<60; i++) minutes.push(i > 9 ? i : '0'+i);
                    return minutes;
                })()
            },
            {
                divider: true,  // 这是一个分隔符
                content: '分'
            }
        ];
    },
    onChange: function (picker, values, displayValues) {
        // console.log(values);
    }
});



$(function(){
    //选择地区
    Area.init("#area_province","#area_city","#area_area");
    //设置按钮的位置
    $("#n1").css("margin-left",((window.innerWidth-220)/2)+"px");
    $("#n2").css("margin-left",((window.innerWidth-220)/2)+"px");
    $("#n3").css("margin-left",((window.innerWidth-220)/2)+"px");
    $("#n4").css("margin-left",((window.innerWidth-100)/2)+"px");
    // server.req('wechat/service/list',{},function (e) {
    //     // console.log(e)
    //     var strH = "";
    //     if(e.code==0){
    //         var data = e.data;
    //         data.forEach(function (item,index) {
    //             strH = strH + '<label class="skillA" id="skill'+item.id+'" onclick="selectSkill('+item.id+',&apos;'+item.title+'&apos;)">'+item.title+'</label>';
    //         })
    //     $("#info2-body").html(strH);
    //     }
    // });

    server.req('/wechat/studies/all',{},function (e) {
        var strH = "";
        if(e.code==0){
            var data = e.data;
            data.forEach(function (item,index) {
                strH = strH + '<label class="skillA" id="skill'+item.id+'" onclick="selectSkill('+item.id+',&apos;'+item.title+'&apos;)">'+item.title+'</label>';
            })
            $("#info2-body").html(strH);
        }
    })

    //获取当前用户的大师资格申请
    server.req('wechat/teacher/getByMemberId',{},function (e) {
        console.log("get teacher iinf..")
        console.log(e)
        if(e.code==0){
            var data = e.data;
            if(e.data!=null){
                dealing();
                if(data.status==-1){
                    $("#status").text("申请已被驳回，你不能再次申请");
                }else if(data.status==2){
                    $("#status").text("恭喜，申请已被批准");
                }
            }
        }
    });
})